printInput.js ➔ createInputSource   C
last analyzed

Complexity

Conditions 12
Paths 20

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
nc 20
nop 3
dl 0
loc 50
rs 5.3904
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A printInput.js ➔ ... ➔ ??? 0 3 1

How to fix   Complexity   

Complexity

Complex classes like printInput.js ➔ createInputSource often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import sourceAutocomplete   from './sourceAutocomplete'
2
import sourceOption   from './sourceOption'
3
import {
4
  abeExtend
5
  ,User
6
} from '../../../'
7
8
export function getAttributes(params) {
9
  var attributes = ''
10
  if(params.key != null) attributes += `id="${params.key}" data-id="${params.key}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
11
  if(params.value != null) attributes += ` value="${params.value}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
12
  if(params['max-length'] != null) attributes += ` data-maxlength="${params['max-length']}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
13
  if(params.reload != null) attributes += ` reload="${params.reload}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
14
  if(params.order != null) attributes += ` tabIndex="${params.order}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
15
  if(params.required != null) attributes += ` data-required="${params.required}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
16
  if(params.display != null) attributes += ` data-display="${params.display}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
17
  if(params.visible != null) attributes += ` data-visible="${params.visible}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
18
  if(params.autocomplete != null) attributes += ` data-autocomplete="${params.autocomplete}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
19
  if(params.placeholder != null) attributes += ` placeholder="${params.placeholder}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
  if(params.thumbs != null) attributes += ` data-size="${params.thumbs}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
21
  if(params.toolbar != null) attributes += ` data-toolbar="${params.toolbar}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
22
  if(params.multiple != null) attributes += ` ${params.multiple}`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
23
  if(params.disabled != null) attributes += ` ${params.disabled}`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
24
  return attributes
25
}
26
27
export function getLabel(params) {
28
  var desc = params.desc + ((params.required) ? ' *' : '')
29
  return `<label class="control-label" for="${params.key}" >
30
            ${desc}
31
          </label>`
32
}
33
34
export function hint(params) {
35
  if (params.hint) {
36
    return `<p class="abe-hint help-block">
37
        <span class="glyphicon glyphicon-info-sign"></span>&nbsp;<em>${params.hint}</em>
38
      </p>`
39
  }
40
41
  return ''
42
}
43
44
export function createInputSource(attributes, inputClass, params) {
45
  var inputSource = `<div class="parent-${params.type} parent-${params.key}" data-parent="${params.key}">`
46
  var lastValues
47
  if(params.autocomplete != null && params.autocomplete === 'true') {
48
    if(params.sourceString.indexOf('http') === 0) lastValues = params.source
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
49
    else lastValues = JSON.stringify(params.source).replace(/\'/g, '&quote;')
50
    inputSource += '<div class="autocomplete-result-wrapper">'
51
    if(params.autocomplete != null && params.autocomplete === 'true' && params.prefill === 'true') {
52
      inputSource += `<div  class="autocomplete-refresh" value=''
53
                            data-autocomplete-refresh="true"
54
                            data-autocomplete-refresh-sourcestring="${params.sourceString}"
55
                            data-autocomplete-refresh-prefill-quantity="${params['prefill-quantity']}"
56
                            data-autocomplete-refresh-key="${params.key}"
57
                            data-autocomplete-data-display="${params.display}" >
58
                        <span class="glyphicon glyphicon-refresh"></span>
59
                      </div>`
60
    }
61
    Array.prototype.forEach.call(params.value, (val) => {
62
      inputSource += sourceAutocomplete(val, params)
63
    })
64
    inputSource += `</div><input value="" type="text" autocomplete="off" data-value='${lastValues}' ${attributes} class="${inputClass}" />`
65
  }
66
  else {
67
    lastValues = JSON.stringify(params.value).replace(/\'/g, '&quote;')
68
    inputSource += `<select ${attributes} class="${inputClass}" last-values='${lastValues}'>`
69
70
    // if (!params.required) inputSource += '<option value=\'\'></option>'
71
    var options = ''
72
    if(typeof params.source === 'object' && Object.prototype.toString.call(params.source) === '[object Array]') {
73
      Array.prototype.forEach.call(params.source, (val) => {
74
        options += sourceOption(val, params)
75
      })
76
    }else{
77
      options += sourceOption(params.source, params)
78
    }
79
80
    var defaultValueSelected = 'selected=selected'
81
    if (options.indexOf('selected') > -1) {
82
      defaultValueSelected = ''
83
    }
84
    if (params.required) inputSource += `<option value=\'\' value="" disabled ${defaultValueSelected}>Select ${params.desc.toLowerCase()}...</option>`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
85
    if (!params.required) inputSource += `<option value=\'\' value="" ${defaultValueSelected}></option>`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
86
    inputSource += options
87
88
    inputSource += '</select>'
89
  }
90
  inputSource += `${hint(params)}</div>`
91
92
  return inputSource
93
}
94
95
export function createInputRich(attributes, inputClass, params) {
96
  var buttons = [
97
    { icon: 'bold',                  title: 'Bold (Ctrl+B)',          action: 'bold',         param: '',         hotkey: 'b',     key:'b' },
98
    { icon: 'ti-Italic',             title: 'Italic (Ctrl+I)',        action: 'italic',       param: '',         hotkey: 'i' },
99
    { icon: 'ti-underline',          title: 'Underline (Ctrl+U)',     action: 'underline',    param: '',         hotkey: 'u' },
100
    { icon: 'strikethrough',         title: 'Strikethrough',          action: 'strikethrough',param: '' ,                         key:'s' },
101
    { icon: 'ti-paint-bucket',       title: 'Text color',             action: 'forecolor',    param: '',         popup: 'color' },
102
    { icon: 'ti-paint-bucket bg',    title: 'Background color',       action: 'highlight',    param: '',         popup: 'color' },
103
    { icon: 'ti-align-left',         title: 'Left',                   action: 'align',        param: 'left' },
104
    { icon: 'ti-align-center',       title: 'Center',                 action: 'align',        param: 'center' },
105
    { icon: 'ti-align-right',        title: 'Right',                  action: 'align',        param: 'right' },
106
    { icon: 'ti-align-justify',      title: 'Justify',                action: 'align',        param: 'justify' },
107
    { icon: 'ti-text ti-text-sub',   title: 'Subscript',              action: 'subscript',    param: '' },
108
    { icon: 'ti-text ti-text-sup',   title: 'Superscript',            action: 'superscript',  param: '' },
109
    { icon: 'ti-shift-right-alt',    title: 'Indent',                 action: 'indent',       param: '' },
110
    { icon: 'ti-shift-left-alt',     title: 'Outdent',                action: 'indent',       param: 'outdent' },
111
    { icon: 'ti-list',               title: 'Unordered list',         action: 'list',         param: '' },
112
    { icon: 'ti-list-ol',            title: 'Ordered list',           action: 'list',         param: 'ordered' },
113
    { icon: 'ti-eraser',             title: 'Remove format',          action: 'removeFormat', param: '' },
114
    { icon: 'ti-link',               title: 'Add link',               action: 'insertLink',   param: '',         popup: 'link' },
115
    { icon: 'console',               title: 'Code style',             action: 'code',         param: '',                          key:'{code}' },
116
    { icon: 'ti-image',              title: 'media',                  action: 'media',        param: '',         popup: 'image' },
117
    { icon: 'ti-face-smile',         title: 'smiley',                 action: 'smiley',       param: '',         popup: 'smiley' },
118
  ]
119
  if(params.toolbar !== '*') params.toolbar = params.toolbar.split(',')
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
120
  var inputRich = `<div class="parent-${params.type} parent-${params.key}" data-parent="${params.key}">
121
                  <div class="wysiwyg-container rich">
122
                    <div class="wysiwyg-toolbar wysiwyg-toolbar-top">`
123
124
  buttons.forEach(function (button) {
125
    if(params.toolbar === '*' || params.toolbar.indexOf(button.action) > -1){
126
      var hotkey = (button.hotkey != null) ? `hotkey="${button.hotkey}"` : ''
127
      var popup = (button.popup != null) ? `data-popup="${button.popup}"` : ''
128
      if (button.popup === 'image') button.action = 'insertImage'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
129
      if (button.action === 'list') button.action = 'insertList'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
130
      inputRich += `<a  class="wysiwyg-toolbar-icon parent-${button.icon}" 
131
                        data-action="${button.action}"
132
                        data-param="${button.param}"
133
                        title="${button.title}"
134
                        ${hotkey}
135
                        ${popup}
136
                        href="#">
137
                      <span class="glyphicon theme-icon ${button.icon}">${(button.key) ? button.key : ''}</span>
138
                    </a>`
139
    }
140
  })
141
142
  inputRich +=    `</div>
143
                  <textarea class="${inputClass} form-rich" ${attributes} rows="4">${params.value}</textarea>
144
                </div>
145
                ${hint(params)}
146
              </div>`
147
148
  return inputRich
149
}
150
151
export function createInputFile(attributes, inputClass, params) {
152
153
  return `<div class="parent-${params.type} parent-${params.key}" data-parent="${params.key}">
154
          <div class="input-group file-upload">
155
            <div class="input-group-addon image">
156
              <span class="glyphicon glyphicon-file" aria-hidden="true"></span>
157
            </div>
158
            <input type="text" ${attributes} class="${inputClass} file-input" />
159
            <div class="upload-wrapper">
160
              <input class="form-control" ${attributes} name="${params.key}" type="file" title="upload a file"/>
161
              <span class="percent">
162
                <span class="glyphicon glyphicon-upload" aria-hidden="true"></span>
163
              </span>
164
            </div>
165
          </div>
166
          <div class="input-error"></div>
167
          ${hint(params)}
168
        </div>`
169
}
170
171
export function createInputTextarea(attributes, inputClass, params) {
172
  return `<div class="parent-${params.type} parent-${params.key}" data-parent="${params.key}">
173
          <textarea class="${inputClass}" ${attributes} rows="4">${params.value}</textarea>
174
            ${hint(params)}
175
          </div>`
176
}
177
178
export function createInputLink(attributes, inputClass, params) {
179
  return `<div class="parent-${params.type} parent-${params.key}" data-parent="${params.key}">
180
          <div class="input-group">
181
            <div class="input-group-addon link">
182
              <span class="glyphicon glyphicon-link" aria-hidden="true"></span>
183
            </div>
184
            <input type="text" ${attributes} class="${inputClass}" />
185
          </div>
186
          ${hint(params)}
187
        </div>`
188
}
189
190
export function createInputImage(attributes, inputClass, params) {
191
  return `<div class="parent-${params.type} parent-${params.key}" data-parent="${params.key}">
192
          <div class="input-group img-upload">
193
            <div class="input-group-addon image">
194
              <span class="glyphicon glyphicon-picture" aria-hidden="true"></span>
195
            </div>
196
            <input type="text" ${attributes} class="${inputClass} file-input" />
197
            <div class="upload-wrapper">
198
              <input class="form-control" ${attributes} name="${params.key}" type="file" title="upload an image"/>
199
              <span class="percent">
200
                <span class="glyphicon glyphicon-upload" aria-hidden="true"></span>
201
              </span>
202
            </div>
203
          </div>
204
          <div class="input-error">
205
        </div>
206
        ${hint(params)}
207
      </div>`
208
}
209
210
export function createInputText(attributes, inputClass, params) {
211
  return `<div class="parent-${params.type} parent-${params.key}" data-parent="${params.key}">
212
          <div class="input-group">
213
            <div class="input-group-addon">
214
              <span class="glyphicon glyphicon-font" aria-hidden="true"></span>
215
            </div>
216
            <input type="text" ${attributes} class="${inputClass}" />
217
            </div>
218
            ${hint(params)}
219
          </div>`
220
}
221
222
/**
223
 * Print form input based on input data type {Textarea | text | meta | link | image | ...}
224
 * && add appropriate attributs / data-attributs
225
 * @return {String|html} input / input group ...
226
 */
227
export function printInput (params, root) {
228
  params = abeExtend.hooks.instance.trigger('beforeEditorInput', params)
229
  var userWorkflow = (root.user != null) ? root.user.role.workflow : ''
230
  var res = `<div class="form-group" data-precontrib-templates="${params.precontribTemplate}">`
231
  var inputClass = 'form-control form-abe'
232
  res += getLabel(params)
233
234
  params.placeholder = params.placeholder || ''
235
  params.value = params.value || ''
236
  
237
  if(typeof params.value === 'string') params.value = params.value.replace(/\"/g, '&quot;')
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
238
  if(!(params.toolbar != null)) params.toolbar = '*'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
239
240
  params.disabled = ''
241
  if (params.tab !== 'slug' && !User.utils.isUserAllowedOnRoute(userWorkflow, `/abe/operations/edit/${params.status}`)) {
242
    params.disabled = 'disabled="disabled"'
243
  }
244
  var attributes = getAttributes(params)
245
246
  if(params.source != null) {
247
    params.multiple = ((params['max-length'] == null || params['max-length'] > 1) && params.source.length > 0) ? 'multiple' : ''
248
    params.disabled = (params.source.length <= 0) ? 'disabled' : ''
249
    res += createInputSource(getAttributes(params), inputClass, params)
250
  }
251
  else if (params.type.indexOf('rich') >= 0) res += createInputRich(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
252
  else if (params.type.indexOf('file') >= 0) res += createInputFile(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
253
  else if (params.type.indexOf('textarea') >= 0) res += createInputTextarea(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
254
  else if (params.type.indexOf('link') >= 0) res += createInputLink(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
255
  else if (params.type.indexOf('image') >= 0) res += createInputImage(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
256
  else res += createInputText(attributes, inputClass, params)
257
258
  res += '</div>'
259
  res = abeExtend.hooks.instance.trigger('afterEditorInput', res, params)
260
261
  return res
262
}